package com.flyoil.petromp.ui.fragment.fragment_statiscs;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.cnpc.fyviewlibrary.view.NoScrollViewPager;
import com.cnpc.fyviewlibrary.viewpager.FragmentPagerAdapter;
import com.flyoil.petromp.R;
import com.flyoil.petromp.base.BaseFragment;
import com.flyoil.petromp.ui.fragment.fragment_order.CourseCertainListFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by songzhiiyn on 2017/9/27.
 * 统计页面
 */

public class StatisticsFragment extends BaseFragment {
    private List<Fragment> fragments;
    private NoScrollViewPager viewPager;
    private FragmentPagerAdapter adapter;
    private TextView tv_department, tv_supplier;


    @Override
    protected int getContentViewResId() {
        return R.layout.fragment_statics;
    }

    @Override
    protected void initViews() {
        super.initViews();
        viewPager = $(R.id.viewpager_fragment_statics_list);
        viewPager.setScrollble(false);
        tv_department = $(R.id.tv_statics_fragment_department);
        tv_supplier = $(R.id.tv_statics_fragment_supplier);
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        tv_department.setOnClickListener(onClickListener);
        tv_supplier.setOnClickListener(onClickListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int position = 0;
            switch (view.getId()) {
                case R.id.tv_statics_fragment_department:
                    position = 0;
                    break;
                case R.id.tv_statics_fragment_supplier:
                    position = 1;
                    break;
            }
            viewPager.setCurrentItem(position);
            setViewStatus(position);
        }
    };

    @Override
    protected void initdatas() {
        super.initdatas();
        fragments = new ArrayList<Fragment>();
        fragments.add(new StatisticsDepartmentFragment());
        fragments.add(new StatisticsSupplierFragment());
        adapter = new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        };
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(fragments.size());
        setViewStatus(0);
    }

    private void setViewStatus(int position) {

        switch (position) {
            case 0:
                tv_department.setTextColor(getResources().getColor(R.color.home_color));
                tv_supplier.setTextColor(getResources().getColor(R.color.white));
                tv_department.setBackgroundResource(R.drawable.shape_white_lift_backgroud);
                tv_supplier.setBackgroundResource(R.drawable.shape_red_right_backgroud);
                break;
            case 1:
                tv_department.setTextColor(getResources().getColor(R.color.white));
                tv_supplier.setTextColor(getResources().getColor(R.color.home_color));
                tv_department.setBackgroundResource(R.drawable.shape_red_lift_backgroud);
                tv_supplier.setBackgroundResource(R.drawable.shape_white_right_backgroud);
                break;
        }
    }

    ;
}
